<?php

/**
 * 
 */
 
use Workerman\Worker;
use Workerman\Mysql;

 class mod_debuger{
	
	public function entry($param){
		return $this->do_mod_debuger($param);
	}

		
	/** 
	* do_mod_settings_user  
	* 
	* @access private 
	* @param $param batch
	* @since 1.0 
	* @return array(errcode,errmsg,rtv) 
	*/
	private function do_mod_debuger($param){
		$action = $param['action'];
		try{
			if(empty($action) || $action==""){
				$sql = "select id, command from hf_mes_debug_commands order by id desc limit 50;";
				$dp=sql_query($sql);
				$html = new stdClass();
				$html->data = $dp;
				$obj = $html;
			}

			if($action == "add"){
				$command = $_POST["command"];
				sql_insert("hf_mes_debug_commands",array('command'=>$command));
				$obj = "done";
			}

			if($action == "select"){
				$id = $_POST["id"];
				$ret_array = array();
				$sql = "select command from hf_mes_debug_commands where id='$id' LIMIT 1;";
				$dp=sql_query($sql);
				if(count($dp)<=0){
					$ret_array['errcode'] = 4001;
					$ret_array['msg'] = "";
					$obj = json_encode($ret_array);
					throw new EXception( $obj );
				}

				$ret_array['errcode'] = 0;
				$ret_array['msg'] = $dp[0]['command'];
				$obj = json_encode($ret_array);
				throw new EXception( $obj );
			}

		}catch(EXception $e){
			return array("errcode"=> 4002,"errmsg"=>"","rtval"=>json_decode($e->getMessage()));
		}

		return array("errcode"=> 0,"errmsg"=>"","rtval"=>$obj);
	}

	/** 
	* create  
	* 通过 call_user_func 获得本class的实例
	* 
	* @access public 
	* @since 1.0 
	* @return object 本类的实例
	*/	
    public static function create(){  
        static $instance;
        if (!$instance){  
			$instance = new mod_debuger();  
        }
		return $instance;  
    }   
 }